<?php
namespace app\index\service;


use app\index\model\SealModel;
use app\index\model\SealWaiModel;
use app\index\model\UserModel;
use think\Db;

class XingService extends CommonService
{
    public function check_seal_name($name, $id=0){
        return !!SealModel::where(['comid'=>$this->userinfo['comid'],'name'=>$name,'deleted_user'=>0])->where('id','neq', $id)->find();
    }
    public function get_seal_state(){
        return ['正常','停用','作废','销毁'];
    }


    public function get_seal_wainame($name){
        $str = '-';
        $exist = SealWaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0])
            ->where(['isturn'=>1,'status'=>1,'isfan'=>0])
            ->where(Db::raw("find_in_set('".$name."',sealname)"))
            ->find();
        if($exist){
            $str = '外带';
        }
        return $str;
    }

    public function get_sealzhi_shenlei(){
        return ['新刻','换刻','补刻'];
    }
    public function get_sealzhi_yinlei(){
        return ['公章','名章','财务专用章','合同专用章','项目专用章','农民工工资专用章'];
    }
    public function get_sealzhi_yinxing(){
        return ['圆形','椭圆形','方章','长条章','其他'];
    }
    public function get_sealzhi_yinhan(){
        return ['已出具','未出具'];
    }
    public function get_notice_tongtype(){
        return [
            1=>'通知',
            2=>'公告',
            3=>'决定',
            4=>'通报',
            5=>'其他',
        ];
    }

    public function get_notice_tongtype_show($tongtype=''){
        $arr = $this->get_notice_tongtype();
        return isset($arr[$tongtype]) ? $arr[$tongtype] : '';
    }

    public function get_notice_jietype(){
        return [
            'all' =>'全部',
            'role' =>'角色',
            'dept' =>'部门',
            'gang' =>'岗位',
            'user' =>'用户',
        ];
    }

    public function get_notice_jietype_show($jietype=''){
        $arr = $this->get_notice_jietype();
        return isset($arr[$jietype]) ? $arr[$jietype] : '';
    }


    public function get_notice_jieer_by_jietype($jietype, $jieer){
        $uidArr = [];
        if($jietype == 'all'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->column('id');
        }
        if($jietype == 'role'){
            $where = '';
            foreach (explode(',', $jieer) as $v){
                if(empty($where)){
                    $where = "find_in_set(".$v.",`roleid`)";
                }else{
                    $where .= "or find_in_set(".$v.",`roleid`)";
                }
            }
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->where($where)->column('id');
        }
        if($jietype == 'dept'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('deptid','in',$jieer)->column('id');
        }
        if($jietype == 'gang'){
            $where = '';
            foreach (explode(',', $jieer) as $v){
                if(empty($where)){
                    $where = "find_in_set(".$v.",`gangid`)";
                }else{
                    $where .= "or find_in_set(".$v.",`gangid`)";
                }
            }
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])->where($where)->column('id');
        }
        if($jietype == 'user'){
            $uidArr = UserModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1])
                ->where('id','in',$jieer)->column('id');
        }

        return implode(',', $uidArr);
    }

    public function get_notice_status_show($status=''){
        $arr = [
            0 => '草稿',
            1 => '已发布',
            2 => '作废',
        ];
        return isset($arr[$status]) ? $arr[$status] : '';
    }
    public function get_asset_state(){
        return [
            1=>'闲置',
            2=>'在用',
            3=>'维修',
            4=>'报废',
        ];
    }

    public function get_asset_state_show($state=''){
        $arr = $this->get_asset_state();
        return isset($arr[$state]) ? $arr[$state] : '';
    }



    public function get_meet_status($startdt, $enddt){
        $str = '';
        $curdt = date("Y-m-d H:i:s");
        if($curdt < $startdt){
            $str = '未开始';
        }else{
            if($curdt < $enddt){
                $str = '进行中';
            }else{
                $str = '已结束';
            }
        }
        return $str;
    }



}
